package com.navinfo.platform.bigdata.hive.dto;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class VehicleStatusAdditionDto {
    private String types;
    private String statusValue;

    public VehicleStatusAdditionDto(String types, String statusValue) {
        this.types = types;
        this.statusValue = statusValue;
    }
    public String getTypes() {
        return types;
    }
    public void setTypes(String types) {
        this.types = types;
    }
    public String getStatusValue() {
        return statusValue;
    }
    public void setStatusValue(String statusValue) {
        this.statusValue = statusValue;
    }

    public static List<VehicleStatusAdditionDto> parseToList(String statusList) {
        if (statusList == null) {
            return Collections.emptyList();
        }
        List<VehicleStatusAdditionDto> result = new ArrayList<>();
        for (String data : JSON.parseObject(statusList, new TypeReference<List<String>>() {    })) {
            String[] arr = data.split("_");
            result.add( new VehicleStatusAdditionDto(arr[0], arr[1]));
        }
        return result;
    }


    public static List<VehicleStatusAdditionDto> parseStrToList(String statusList) {
        if (statusList == null) {
            return Collections.emptyList();
        }
        List<VehicleStatusAdditionDto> result = new ArrayList<>();
        //mileage|5862,mileageDD|900
        String[] arr = statusList.split(",");
        for (String str:arr) {
            String[] subArr = str.split("_");
            result.add( new VehicleStatusAdditionDto(subArr[0], subArr[1]));
        }
        return result;
    }

    public static void main(String args[]){
        String str = "mileage_5862,mileageDD_900";
        List<VehicleStatusAdditionDto> list = VehicleStatusAdditionDto.parseStrToList(str);
        System.out.println(list.size());
    }
}
